package com.teaRestaurant.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.github.pagehelper.PageInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

@Configuration
//扫面指定的mapper包（此注解也可以放到启动类中，但一般放在配置类中）
@MapperScan("com.teaRestaurant.mapper")
public class MyBatisPlusConfig {
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        //创建Mybatis-Plus拦截器对象
        MybatisPlusInterceptor interceptor=new MybatisPlusInterceptor();
        //new PaginationInnerInterceptor(DbType.MYSQL):创建分页插件，数据库类型是MySQL
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }

    @Bean
    PageInterceptor pageInterceptor(){
        PageInterceptor pageInterceptor = new PageInterceptor();
        Properties properties = new Properties();
        properties.setProperty("helperDialect", "mysql");
        // 由此可进入源码，
        pageInterceptor.setProperties(properties);
        return pageInterceptor;
    }

}
